package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;
/**ControlLayer package sets the location for RegisterController class.
 * 
 * Usually a 'Controller' is the interface between a user interface component
 * and a model (e.g. Register). Controllers should be thin classes, doing little
 * more than mapping user interface events to model functions.
 * 
 * The ModelLayer package is imported, because controllers must be able to access 
 * classes in the ModelLayer - AddressBook, DVDRegister and LoanRegister.
 * ---------------------------------------------------------------------------------
 * RegisterController class is devided in 3 sections. In each section(except the first
 * one) methods with similar functionalities are placed. 
 *  
 *  Section Contents:
 *  Variables
 *  Constructors
 *      - RegisterController()
 *  Methods
 *      - getDVD()
 *      - printDVD()
 *      - createDVD()
 *      - deleteDVD()
 *      - updateDVD()
 *      - listAllDVD()
 */
public class RegisterController
{
    //RegisterCntroller has to store the processed information somewhere. For the 
    //purpose to provide a container for the controller, the following object
    //reference(association) is needed.
    private DvdRegister register; // Reference to RegisterCntroller.
    
  /** CONSTRUCTORS */
  public RegisterController()
  {
        register = DvdRegister.getInstance();
         //Sets the container for storing items.
  }
    
  /** METHODS */
  public DVD getDVD(String dvd_id)
  //Finds a DVD by exact id.
  {
      return register.getDVD(dvd_id);
  }
    
  public String printDVD(String dvd_id)
  //Prints a DVD by exact id.
  {
      return register.getDVD(dvd_id).showDetails();
  }
    
  public void createDVD(String dvd_id, String title, String artist,
                        String publicationDate)
  //Creates a DVD and store it in the Register.
  {
      if(getDVD(dvd_id)!=null)
      {
          //Prevents from adding persons with the same id.
          System.out.println("There is already a DVD with id "+ dvd_id +".");
      }
      else
      {
          register.addDVD(dvd_id, title, artist, publicationDate); 
      }
  }
  
  public void deleteDVD(String dvd_id)
  //Deletes a DVD by exact id.
  {
            register.deleteDVD(dvd_id);
  }
  
  public void updatemyDVD(String dvd_id, String title, String artist,
                            String publicationDate)
  //Updates a DVD by exact id,
  {
      register.updateDVD(getDVD(dvd_id), dvd_id, title, artist, publicationDate);
  }
  
  public void listAllDvds()
  //Shows all DVD in the Register.
  {
      if(register.findDVD().isEmpty())
      {
          System.out.println("There's no list of DVDS at the time");
      }
      int index=0;
      while(index<register.findDVD().size())
      {
          System.out.println(register.findDVD().get(index).toString());
          System.out.println("This DVD has " + register.findDVD().get(index).copiesCollection().size() +" copies");
          int i=0;
          while (i<register.findDVD().get(index).copiesCollection().size())
          {
              int k=i+1;
              System.out.println("Copy nr."+k);
              System.out.println(register.findDVD().get(index).copiesCollection().get(i).toString());
              i++;
          }
            System.out.println("___________________________________________________________");
            index++;
      }
  }
}
